﻿(function ($) {
    UtilityClass = function () {
    };

    UtilityClass.prototype = {
        init: UtilityClass,
        
/*--------------------------------------------------------------------------------------
* Check input in element id
*----------------------------------------------------------------------------------------*/
        //Check is null input
        isNull: function(element) {
            return (typeof element === "undefined" || element === null || element === Object);
        },
        
        //Check is null or empty input 
        isNullOrEmpty: function(element) {
            return (Helpers.isNull(element) || element === "");
        },
        
        //Get url parameter in url of browser
        //parameter: name search in url 
        getURLParameter: function(name) {
            var result = decodeURI(
                (RegExp(name + '=' + '(.+?)(&|$)').exec(location.search) || [, null])[1]
            );
            if (result == "null")
                return null;
            return result;
        },
        
        //Show message confirm 
        //Parameter: message: string of message, fcallback: function call back if user click ok, value: value is parameters of fcallback
        showMessage: function(message, fcallback, value) {
            var result = confirm(message);

            if (result == true) {
                fcallback(value);
            } else {

            }
        },
        
        //Check input is date
        //Parameter: dtYear: value of year, dtMonth: value of month, dtDay: value of day
        checkInputIsDate: function(dtYear, dtMonth, dtDay) {
            var arrayDate = [dtYear, dtMonth, dtDay];
            //loop array date check if null and string empty then return false
            for (var i = 0; i < arrayDate.length; i++) {
                if ($.trim(arrayDate[i]) != "" && parseInt(arrayDate[i]).toString != "NaN") {
                    var temp = (!/[^0-9]/g.test(arrayDate[i]));
                    if (!temp) {
                        return false;
                    }
                }
            }
            if (dtYear.toString() != "" && dtMonth != "" && dtDay != "") {
                if (dtMonth < 1 || dtMonth > 12) {
                    return false;
                } else if (dtDay < 1 || dtDay > 31) {
                    return false;
                } else if ((dtMonth == 4 || dtMonth == 6 || dtMonth == 9 || dtMonth == 11) && dtDay == 31) {
                    return false;
                } else if (dtMonth == 2) {
                    var isleap = (dtYear % 4 == 0 && (dtYear % 100 != 0 || dtYear % 400 == 0));
                    if (dtDay > 29 || (dtDay == 29 && !isleap))
                        return false;
                }
            }
            return true;

        },
        
        //The function check input is time 
        checkInputIsTime: function(hour, minute, errorElementId) {
            if (parseInt(hour).toString != "NaN" && parseInt(minute).toString != "NaN") {
                if (parseInt(hour) < 0 || parseInt(hour) >= 24 || parseInt(minute) < 0 || parseInt(minute) >= 60) {
                    Helpers.AddErrorInCheckDate(errorElementId);
                    return 0;
                }
                return 1;
            }
            return 0;
        },
        
        //add error message in html
        //param : form element class or id, and pls add ul with id='validateSummary' in html, and add attr with name textLbl is name of display
         errorMessageSummaryIsDateTime: function(formElement, isError) {
             try {
                 //check error in lat lon if exist error is visible spanError or SpanErrorTwo
                 checkErrorLatLon();
             } catch(ex) {
             }
             var counterShowError = 0;
             var couterErrorLat = 0;
             var couterErrorLon = 0;
             var counterErrorLatEnd = 0;
             var counterErrorLonEnd = 0;
             
             //Check if form exist error and form is not valid
             if (!$(formElement).valid()) {
                 $("#validateSummary").empty();
                 $("#validateSummary").append('<li>' + "下記の項目に誤りがあるかご確認下さい。" + '</li>');
                 
                 //this function find class "input-validation-error" add to sumary error in header
                 $(formElement).find('.input-validation-error').each(function() {
                     $("#validateSummary").css("display", "block");
                     var attr = $(this).attr('textLbl');
                     // For some browsers, `attr` is undefined; for others,
                     // `attr` is false.  Check for both.
                     if (typeof attr !== 'undefined' && attr !== false) {
                         if (attr == "北緯東経 北緯" || attr == "北緯東経 度" || attr == "北緯東経 分" || attr == "北緯東経 秒"
                             || attr == "東経 分" || attr == "東経 度" || attr == "東経 秒" || attr == "北緯東経"
                             || attr == "北緯 度" || attr == "北緯 分" || attr == "北緯 秒") {

                             if (attr == "北緯東経 北緯" || attr == "北緯東経 度" || attr == "北緯東経 分" || attr == "北緯東経 秒"
                                 || attr == "北緯 度" || attr == "北緯 分" || attr == "北緯 秒") {
                                
                                 couterErrorLat++;

                             } else if (attr == "東経 度" || attr == "東経 分" || attr == "東経 秒") {
                                
                                 couterErrorLon++;
                             }

                         }
                         if (attr == "北緯東経 北緯" || attr == "北緯東経 度" || attr == "北緯東経 分" || attr == "北緯東経 秒"
                            || attr == "東経 分" || attr == "東経 度" || attr == "東経 秒" || attr == "北緯東経"
                            || attr == "北緯 度" || attr == "北緯 分" || attr == "北緯 秒") {
                            counterShowError++;
                            
                        } 
                         if (counterShowError == 1) {
                            attr = "北緯東経";
                             $("#validateSummary").append('<li>' + attr + '</li>');
                        }else {
                              var counterDuplicate = 0;
                          
                              var liIds = $('#validateSummary li').map(function(i,n) {
                                    return $(n).text();
                                }).get().join(',');
                              var listListId = liIds.split(",");
                              for (var index = 0; index < listListId.length; index++) {
                                  if (listListId[index] == attr) {
                                      counterDuplicate++;
                                  }
                              }
                              if (counterDuplicate == 0) {
                                $("#validateSummary").append('<li>' + attr + '</li>');
                              }
                          }
                    }
                 });
                 var errorLatLonInFunction = 0;
                 if ($('#spanError').css("visibility") == "visible") {
                     $("#validateSummary").append('<li>' + "北緯東経" + '</li>');
                     couterErrorLat++;
                     errorLatLonInFunction++;
                 }
                 if ($('#spanErrorTwo').css("visibility") == "visible") {
                     $("#validateSummary").append('<li>' + "北緯東経" + '</li>');
                     couterErrorLon++;
                     errorLatLonInFunction++;
                 }
                 if ($('#spanErrorEnd').css("visibility") == "visible") {
                     $("#validateSummary").append('<li>' + "北緯東経" + '</li>');
                     counterErrorLatEnd++;
                     errorLatLonInFunction++;
                 }
                 if ($('#spanErrorTwoEnd').css("visibility") == "visible") {
                     $("#validateSummary").append('<li>' + "北緯東経" + '</li>');
                     counterErrorLonEnd++;
                     errorLatLonInFunction++;
                 }
                 if (errorLatLonInFunction != 0) {
                     $("#validateSummary").append('<li>' + "北緯東経" + '</li>');
                 }

                 if (couterErrorLat == 0) {
                     $("#spanError").css("visibility", "hidden");
                 } else {
                      $("#spanError").css("visibility", "visible");
                        $("#spanError").text("緯度を正しく入力してください");
                 }
                 if (couterErrorLon == 0) {
                     $("#spanErrorTwo").css("visibility", "hidden");
                 } else {
                      $("#spanErrorTwo").css("visibility", "visible");
                                 $("#spanErrorTwo").text("経度を正しく入力してください");
                 }
                 
                 if (counterErrorLatEnd == 0) {
                     $("#spanErrorEnd").css("visibility", "hidden");
                 } else {
                      $("#spanErrorEnd").css("visibility", "visible");
                        $("#spanErrorEnd").text("緯度を正しく入力してください");
                 }
                 if (counterErrorLonEnd == 0) {
                     $("#spanErrorTwoEnd").css("visibility", "hidden");
                 } else {
                      $("#spanErrorTwoEnd").css("visibility", "visible");
                                 $("#spanErrorTwoEnd").text("経度を正しく入力してください");
                 }
                 
                 //Check if form is not valid and exist error
                 if (isError) {
                     $("#validateSummary").empty();
                     $("#validateSummary").append('<li>' + "下記の項目に誤りがあるかご確認下さい。" + '</li>');

                     Helpers.addErrorInSummary(formElement);
                 }
                 
                 var liIds = $('#validateSummary li').map(function(i,n) {
                    return $(n).text();
                }).get().join(',');
                var listListId = liIds.split(",");
                 var listNew = [];
                for (var index = 0; index < listListId.length; index++) {
                    if (listNew.length >= 1) {
                        var counterDuplicatchListNew = 0;
                        for (var indexOfListNew = 0; indexOfListNew < listNew.length; indexOfListNew++) {
                            if (listListId[index] == listNew[indexOfListNew]) {
                                counterDuplicatchListNew++;
                            }
                        }
                        if (counterDuplicatchListNew == 0) {
                            listNew.push(listListId[index]);
                        }
                    } else {
                        listNew.push(listListId[index]);
                    }
                }
                 
                 $("#validateSummary").empty();
                 for (var indexOfListNewAdd = 0; indexOfListNewAdd < listNew.length; indexOfListNewAdd++) {
                    $("#validateSummary").append('<li>' + listNew[indexOfListNewAdd] + '</li>');
                 }
             }
             

             //Check if form is valid and is error
             else if (isError) {
                
                 $("#validateSummary").empty();
                 $("#validateSummary").append('<li>' + "下記の項目に誤りがあるかご確認下さい。" + '</li>');

                 Helpers.addErrorInSummary(formElement);
             }

                 if ($('#spanError').css("visibility") == "visible" )
                {
                    couterErrorLat++;
                }
                if ($('#spanErrorTwo').css("visibility") == "visible") {
                        couterErrorLon++;
                }
             
             if (couterErrorLat == 0) {
                 $("#spanError").css("visibility", "hidden");
             } else {
                  $("#spanError").css("visibility", "visible");
                                 $("#spanError").text("緯度を正しく入力してください");
             }
             if (couterErrorLon == 0) {
                 $("#spanErrorTwo").css("visibility", "hidden");
             } else {
                  $("#spanErrorTwo").css("visibility", "visible");
                                 $("#spanErrorTwo").text("経度を正しく入力してください");
             }


             var liIds = $('#validateSummary li').map(function(i,n) {
                    return $(n).text();
                }).get().join(',');
                var listListId = liIds.split(",");
                 var listNew = [];
                for (var index = 0; index < listListId.length; index++) {
                    if (listNew.length >= 1) {
                        var counterDuplicatchListNew = 0;
                        for (var indexOfListNew = 0; indexOfListNew < listNew.length; indexOfListNew++) {
                            if (listListId[index] == listNew[indexOfListNew]) {
                                counterDuplicatchListNew++;
                            }
                        }
                        if (counterDuplicatchListNew == 0) {
                            listNew.push(listListId[index]);
                        }
                    } else {
                        listNew.push(listListId[index]);
                    }
                }
                 
                 $("#validateSummary").empty();
                 for (var indexOfListNewAdd = 0; indexOfListNewAdd < listNew.length; indexOfListNewAdd++) {
                    $("#validateSummary").append('<li>' + listNew[indexOfListNewAdd] + '</li>');
                 }
         },
       
        
        //add error in summary
        addErrorInSummary: function(formElement) {
            var counterError = 0;
            var couterErrorLat = 0;
            var couterErrorLon = 0;
            var counterErrorLatEnd = 0;
            var counterErrorLonEnd = 0;

            var counterShowError = 0;
            var errorExist = [];
            

            //find custom validate in field 
            $(formElement).find('.input-validation-error').each(function () {
                $("#validateSummary").css("display","block");
                var attr = $(this).attr('textLbl');
                
                // For some browsers, `attr` is undefined; for others,
                // `attr` is false.  Check for both.
                if (typeof attr !== 'undefined' && attr !== false) {
                    if (attr == "北緯東経 北緯" || attr == "北緯東経 度" || attr == "北緯東経 分" || attr == "北緯東経 秒" 
                            || attr == "東経 分" || attr == "東経 度" || attr == "東経 秒" || attr == "北緯東経"
                            || attr == "北緯 度" || attr == "北緯 分"|| attr == "北緯 秒") {
                            
                            if (attr == "北緯東経 北緯" || attr == "北緯東経 度" || attr == "北緯東経 分"|| attr == "北緯東経 秒"
                                || attr == "北緯 度" || attr == "北緯 分"|| attr == "北緯 秒") {
                                couterErrorLat++;
                                counterError++;
                            } 
                            else if (attr == "東経 度" || attr == "東経 分" || attr == "東経 秒") {
                                couterErrorLon++;
                                counterError++;
                            } 
                        }
                    if (attr == "北緯東経 北緯" || attr == "北緯東経 度" || attr == "北緯東経 分" || attr == "北緯東経 秒"
                        || attr == "東経 分" || attr == "東経 度" || attr == "東経 秒" || attr == "北緯東経"
                        || attr == "北緯 度" || attr == "北緯 分" || attr == "北緯 秒") {
                        counterShowError++;
                                counterError++;
                        
                    } if (counterShowError == 1) {
                            attr = "北緯東経";
                             $("#validateSummary").append('<li>' + attr + '</li>');
                      }else {
                          var counterDuplicate = 0;
                          
                          var liIds = $('#validateSummary li').map(function(i,n) {
                                return $(n).text();
                            }).get().join(',');
                          var listListId = liIds.split(",");
                          for (var index = 0; index < listListId.length; index++) {
                              if (listListId[index] == attr) {
                                  counterDuplicate++;
                              }
                          }
                          if (counterDuplicate == 0) {
                            $("#validateSummary").append('<li>' + attr + '</li>');
                                counterError++;
                          }
                      }
                }
                
            });
           
            
            //error handle input byte string 
            $(formElement).find('.display-error').each(function () {
                    var idElement = $(this).attr('id');
                if ($(this).css("visibility") == "visible" ) {
                    $("#validateSummary").css("display","block");
                    var attrCustom = $(this).attr('textLblCustom');
                    var attr = $(this).attr('data-text-displayname-custom');
                    if (!Helpers.isNullOrEmpty(idElement) && (idElement == "spanError" || idElement == "spanErrorTwo" || idElement == "spanErrorEnd" || idElement == "spanErrorTwoEnd")) {
                        var errorLatLonInFunction = 0;
                        if ($('#spanError').css("visibility") == "visible" )
                           {
                                couterErrorLat++;
                            errorLatLonInFunction++;
                           }
                        if ($('#spanErrorTwo').css("visibility") == "visible") {
                            errorLatLonInFunction++;
                                couterErrorLon++;
                        }
                        
                        if ($('#spanErrorEnd').css("visibility") == "visible" )
                           {
                                counterErrorLatEnd++;
                            errorLatLonInFunction++;
                           }
                        if ($('#spanErrorTwoEnd').css("visibility") == "visible") {
                            errorLatLonInFunction++;
                                counterErrorLonEnd++;
                        }
                        
                        if (errorLatLonInFunction != 0) {
                                counterError++;
                                $("#validateSummary").append('<li>' + "北緯東経" + '</li>');
                        }

                    } else {
                        // For some browsers, `attr` is undefined; for others,
                        // `attr` is false.  Check for both.
                        if ($(this).css("display") !== "none") {
                            if (typeof attr !== 'undefined' && attr !== false) {
                                $("#validateSummary").append('<li>' + attr + '</li>');
                                counterError++;
                            }
	                        if (typeof attrCustom !== 'undefined' && attrCustom !== false) {
                                $("#validateSummary").append('<li>' + attrCustom + '</li>');
                                counterError++;
                            }
                        }
                    }

                    
                }
            });

            //find error date time
            $(formElement).find('.input-validation-error-date').each(function () {
                $("#validateSummary").css("display","block");
                var attr = $(this).attr('textLbl');
                var countErrorExist = 0;
                for (var index = 0; index < errorExist.length; index++) {
                    if (errorExist[index] == attr) {
                        countErrorExist++;
                        counterError++;
                    }
                }
                errorExist.push(attr);
                
                // For some browsers, `attr` is undefined; for others,
                // `attr` is false.  Check for both.
                if (typeof attr !== 'undefined' && attr !== false && $(this).css("visibility") != "hidden" && countErrorExist == 0) {
                    $("#validateSummary").append('<li>' + attr + '</li>');
                    counterError++;
                }

                
            });

             //error handle input byte string 
            $(formElement).find('.dropbox-error').each(function () {
                if ($(this).css("visibility") == "visible") {
                    $("#validateSummary").css("display","block");
                    
                    var attr = $(this).text().split(" を選択してください。");

                    // For some browsers, `attr` is undefined; for others,
                    // `attr` is false.  Check for both.
                    if (typeof attr[0] !== 'undefined' && attr[0] !== false) {
                        $("#validateSummary").append('<li>' + attr[0] + '</li>');
                        counterError++;
                    }
                }
            });
            if (couterErrorLat == 0 && couterErrorLon == 0 && counterErrorLatEnd == 0 && counterErrorLonEnd == 0) {
                $("#validateSummary li").each(function() {
                    if ($(this).text() == "北緯東経") {
                        $(this).remove(); 
                    }
                });
            }
            

            if (couterErrorLat == 0) {
                $("#spanError").css("visibility", "hidden");
            } else {
                  $("#spanError").css("visibility", "visible");  
                                $("#spanError").text("緯度を正しく入力してください");
            }
            if (couterErrorLon == 0) {
                $("#spanErrorTwo").css("visibility", "hidden");
            } else {
                            $("#spanErrorTwo").css("visibility", "visible");
                                $("#spanErrorTwo").text("経度を正しく入力してください");
            }
            
            if (counterErrorLatEnd == 0) {
                $("#spanErrorEnd").css("visibility", "hidden");
            } else {
                  $("#spanErrorEnd").css("visibility", "visible");  
                                $("#spanErrorEnd").text("緯度を正しく入力してください");
            }
            if (counterErrorLonEnd == 0) {
                $("#spanErrorTwoEnd").css("visibility", "hidden");
            } else {
                            $("#spanErrorTwoEnd").css("visibility", "visible");
                                $("#spanErrorTwoEnd").text("経度を正しく入力してください");
            }
            
            if (counterError != 0) {
                $("html, body").animate({ scrollTop: 0 }, 0);

                var liIds = $('#validateSummary li').map(function(i, n) {
                    return $(n).text();
                }).get().join(',');
                var listListId = liIds.split(",");
                
                var listNew = [];
                for (var index = 0; index < listListId.length; index++) {

                    if (listNew.length >= 1) {
                        var counterDuplicatchListNew = 0;
                        for (var indexOfListNew = 0; indexOfListNew < listNew.length; indexOfListNew++) {
                            if (listListId[index] == listNew[indexOfListNew]) {
                                counterDuplicatchListNew++;
                            }
                        }
                        if (counterDuplicatchListNew == 0) {
                            listNew.push(listListId[index]);
                        }
                    } else {
                        listNew.push(listListId[index]);
                    }
                }

                $("#validateSummary").empty();
                for (var indexOfListNewAdd = 0; indexOfListNewAdd < listNew.length; indexOfListNewAdd++) {
                    $("#validateSummary").append('<li>' + listNew[indexOfListNewAdd] + '</li>');
                }
            } else {
                $("#validateSummary").empty();
            }
        },
        
            //function add summary if form not use valid
        errorMessageSummaryIsNotUseValidForm: function(isError) {
            if (isError) {
                $("#validateSummary").empty();
                $("#validateSummary").append('<li>' + "下記の項目に誤りがあるかご確認下さい。" + '</li>');
                $("#validateSummary").append('<li>' + "供用年月日。" + '</li>');
                $("#validateSummary").css("display","block");
            }
        },

            //add error message in html
        //param : form element class or id, and pls add ul with id='validateSummary' in html, and add attr with name textLbl is name of display
        errorMessageSummary: function(formElement) {
            var couterErrorLat = 0;
            var couterErrorLon = 0;
            
            //Check if form is not valid
            if (!$(formElement).valid()) {
                $("#validateSummary").empty();
                $("#validateSummary").append('<li>' + "下記の項目に誤りがあるかご確認下さい。" + '</li>');
                $(formElement).find('.input-validation-error').each(function() {
                    $("#validateSummary").css("display", "block");
                    var attr = $(this).attr('textLbl');
                    var idElement = $(this).attr('id');
                    
                    // For some browsers, `attr` is undefined; for others,
                    // `attr` is false.  Check for both.
                    if (typeof attr !== 'undefined' && attr !== false) {
                        if (attr == "北緯東経 北緯" || attr == "北緯東経 度" || attr == "北緯東経 分" || attr == "北緯東経 秒"
                            || attr == "東経 分" || attr == "東経 度" || attr == "東経 秒" || attr == "北緯東経"
                            || attr == "北緯 度" || attr == "北緯 分" || attr == "北緯 秒") {


                            if (attr == "北緯東経 北緯" || attr == "北緯東経 度" || attr == "北緯東経 分" || attr == "北緯東経 秒"
                                || attr == "北緯 度" || attr == "北緯 分" || attr == "北緯 秒") {
                                $("#spanError").css("visibility", "visible");
                                $("#spanError").text("緯度を正しく入力してください");
                                couterErrorLat++;

                            } else if (attr == "東経 度" || attr == "東経 分" || attr == "東経 秒") {
                                $("#spanErrorTwo").css("visibility", "visible");
                                $("#spanErrorTwo").text("経度を正しく入力してください");
                                couterErrorLon++;
                            }

                        }
                        
                        if (Helpers.isNullOrEmpty(idElement)) {
                            $("#validateSummary").append('<li>' + "北緯東経" + '</li>');
                            couterErrorLon++;
                            couterErrorLat++;
                        } else {
                            $("#validateSummary").append('<li>' + attr + '</li>');
                        }   
                    }
                });
                $(formElement).find('.dropbox-error').each(function () {
                    if ($(this).is(':visible')) {
 
                        $("#validateSummary").css("display","block");
                        $("#validateSummary").css("visibility", "visible");
                    
                        var attr = $(this).text().split(" を選択してください。");

                        // For some browsers, `attr` is undefined; for others,
                        // `attr` is false.  Check for both.
                        if (typeof attr[0] !== 'undefined' && attr[0] !== false) {
                            $("#validateSummary").append('<li>' + attr[0] + '</li>');
                        }
                    }
                });
                    $("html, body").animate({ scrollTop: 0 }, 0);
            }
            //form is valid
            else {
                $("#validateSummary").empty();
                $("#validateSummary").append('<li>' + "下記の項目に誤りがあるかご確認下さい。" + '</li>');
                 //error handle input byte string 
                $(formElement).find('.dropbox-error').each(function () {
                    if ($(this).is(':visible')) {
 
                        $("#validateSummary").css("display","block");
                        $("#validateSummary").css("visibility", "visible");
                    
                        var attr = $(this).text().split(" を選択してください。");

                        // For some browsers, `attr` is undefined; for others,
                        // `attr` is false.  Check for both.
                        if (typeof attr[0] !== 'undefined' && attr[0] !== false) {
                            $("#validateSummary").append('<li>' + attr[0] + '</li>');
                        }
                    }
                });
                var counterShowError = 0;
                $(formElement).find('.display-error').each(function() {
                    if ($(this).css("visibility") != "hidden" ) {
                        var idElement = $(this).attr('id');

                        if (counterShowError == 0) {
                            if (!Helpers.isNullOrEmpty(idElement) && idElement != "validateSummary") {
                                counterShowError++;
                                $("#validateSummary").append('<li>' + "北緯東経" + '</li>');
                                couterErrorLon++;
                                couterErrorLat++;
                            }
                        }
                    }
                });
            }
            if (couterErrorLat == 0) {
                $("#spanError").css("visibility", "hidden");
            }
            if (couterErrorLon == 0) {
                $("#spanErrorTwo").css("visibility", "hidden");
            }
            var counterChild = 0;
           var liIds = $('#validateSummary li').map(function(i,n) {
                return $(n).text();
            }).get().join(',');
            var listListId = liIds.split(",");
            
            for (var index = 0; index < listListId.length; index++) {
            
                    counterChild++;
            }
            
            if (counterChild < 1) {
                $("#validateSummary").empty();
                $("#validateSummary").css("visibility","hidden");
            }

            $("html, body").animate({ scrollTop: 0 }, 0);
        },
        
        topInViewport: function(element) {
            return $(element).offset().top >= $(window).scrollTop() && $(element).offset().top <= $(window).scrollTop() + $(window).height();
        },


        
        //cofirm if next page
        confirmNextPage: function(screenFrom,screenTo) {
            var question = screenFrom + "　をこの内容で更新してよろしいですか。<br />"+
            "次へをクリックすると　" + screenFrom + "　を更新し、<br />"+
            screenTo + "　を表示します。";
             var defer = $.Deferred();
            $('<div></div>')
                .html(question)
                .dialog({
                    autoOpen: true,
                    modal: true,
                    title: '和歌山',
                    buttons: {
                        "戻る": function () {
                            defer.resolve("false");//this text 'false' can be anything. But for this usage, it should be true or false.
                            $(this).dialog("close");
                        },
                        "次へ": function () {
                            defer.resolve("true");//this text 'true' can be anything. But for this usage, it should be true or false.
                            $(this).dialog("close");
                        }
                    }
                });
            return defer.promise();
        },
        
        //Show diaglog confirmation 
        confirmation: function (question) {
            var defer = $.Deferred();
            $('<div></div>')
                .html(question)
                .dialog({
                    autoOpen: true,
                    modal: true,
                    title: '和歌山',
                    buttons: {
                        "はい": function () {
                            defer.resolve("true");//this text 'true' can be anything. But for this usage, it should be true or false.
                            $(this).dialog("close");
                        },
                        "いいえ": function () {
                            defer.resolve("false");//this text 'false' can be anything. But for this usage, it should be true or false.
                            $(this).dialog("close");
                        }
                    }
                });
            return defer.promise();
        },
        
         //Show diaglog confirmation with custom title
        confirmationWithTitle: function (question, titleDilalog) {
            var defer = $.Deferred();
            if (typeof(titleDilalog) == "undefined" ||
                titleDilalog == null) 
            {
                titleDilalog = '和歌山';
            }

            if (titleDilalog.length == 0) 
            {
                titleDilalog = '和歌山';
            }

            $('<div></div>')
                .html(question)
                .dialog({
                    autoOpen: true,
                    modal: true,
                    title: titleDilalog,
                    buttons: {
                        "はい": function () {
                            defer.resolve("true");//this text 'true' can be anything. But for this usage, it should be true or false.
                            $(this).dialog("close");
                        },
                        "いいえ": function () {
                            defer.resolve("false");//this text 'false' can be anything. But for this usage, it should be true or false.
                            $(this).dialog("close");
                        }
                    }
                });
            return defer.promise();
        },
        
        //Show diaglog confirmation 
        messageShowDialog: function (question) {
            var defer = $.Deferred();
            $('<div></div>')
                .html(question)
                .dialog({
                    autoOpen: true,
                    modal: true,
                    title: '和歌山',
                    buttons: {
                        "はい": function () {
                            defer.resolve("true");//this text 'true' can be anything. But for this usage, it should be true or false.
                            $(this).dialog("close");
                        }
                    }
                });
            return defer.promise();
        },
      
            //message confirm delete
        messageConfirmDelete: function () {
            if (!confirm("削除してもよろしいでしょうか?"))
                return false;
            else
                return true;
        },
        
         //message confirm recovery
        messageConfirmRecovery: function () {
            if (!confirm("復帰してもよろしいでしょうか？"))
                return false;
            else
                return true;
        },
/*--------------------------------------------------------------------------------------
* Check input in array element id
*----------------------------------------------------------------------------------------*/
        //Check is null or empty in array 
        //Parameter: array have contains element id
        checkIsNullOrEmptyInArray: function(arrayElementId) {
            var arrayError = [];
            for (var index = 0; index < arrayElementId.length; index++) {
                if (!(isNullOrEmpty($("#" + arrayElementId[index]).val()))) {
                    arrayError.push(arrayElementId[index]);
                }
                if (!checkLengthInArray(arrayError)) {
                    return true;
                }
            }   
            return false;
        },

        //Add class error in array input have contains 'Error'
        //Parameter: array have contains element id have contains 'Error'
        addErrorInArrayInputError: function(arrayElementIdError) {
            if (checkLengthInArray(arrayElementIdError)) {
                for (var index = 0; index < arrayElementIdError.length; index++) {
                    var id = arrayElementIdError[index].split("Error", 1);
                    $("#" + id.toString()).addClass("error");
                }
                return true;
            } 
            return false;
        },
        
            //Add class error in array input
        //parameter: array have contains element id
        addErrorInArrayInput: function (arrayElementId) {
            if (checkLengthInArray(arrayElementId)) {
                for (var index = 0; index < arrayElementId.length; index++) {
                    $("#" + arrayElementId[index].toString()).addClass("error");
                }
                return true;
            }
            return false;
        },
        
        //Check length in array
        checkLengthInArray: function(array) {
            if (array.length < 1) {
                return false;
            } else {
                return true;
            }
        },
        
        //Check Hiragana in array
        //Parameter: array have contains element id
        checkHiraganaInArray: function (arrayElementId) {
            //Check if array element id length = 0. return false
            if (checkLengthInArray(arrayElementId)) {
                var arrayError = [];
                for(var index =0; index < arrayElementId.length; index++)
                {
                    var valueInInput = $("#" + arrayElementId[index]).val();
                    //Check Unicode if between u3040 and u309F is Hiragana
                    if (valueInInput.match(/^[\u3040-\u309F]+$/)) {
                    } else {
                        arrayError.push(arrayElementId[index]);
                    }
                }
                //Check if array error length = 0 is items in arrayElementId not error
                if (!checkLengthInArray(arrayError)) {
                    return true;
                }
            }
            return false;
        },
        
        //Check Katakana in array
        //Parameter: array have contains element id
        checkKatakanaInArray: function (arrayElementId) {
            //Check if array element id length = 0. return false
            if (checkLengthInArray(arrayElementId)) {
                var arrayError = [];
                for(var index =0; index < arrayElementId.length; index++)
                {
                    var valueInInput = $("#" + arrayElementId[index]).val();
                    //Check Unicode if between u3040 and u309F is Katakana
                    if (valueInInput.match(/^[\u30A0-\u30FF]+$/)) {
                    } else {
                        arrayError.push(arrayElementId[index]);
                    }
                }
                //Check if array error length = 0 is items in arrayElementId not error
                if (!checkLengthInArray(arrayError)) {
                    return true;
                }
            } 
            return false;
        },
        
        //Check byte in array
        //Parameter: array have contains element id 
        checkByteInArray: function(arrayElementId) {
            //Check if array element id length = 0. return false
            if (checkLengthInArray(arrayElementId)) {
                var arrayError = [];
                for (var index = 0; index < arrayElementId.length; index++) {
                    //length of input in array 
                    var lengthInputInArray = $("#" + arrayElementId[index]).val().length;
                    // Matches only the 10.. bytes that are non-initial characters in a multi-byte sequence
                    var m = encodeURIComponent($("#" + arrayElementId[index]).val().toString()).match(/%[89ABab]/g);
                    var lengthUnicode = lengthInputInArray + (m ? m.length : 0);
                    //Check length of input in array and byte in input
                    if (lengthInputInArray != lengthUnicode) {
                        arrayError.push(arrayElementId[index]);
                    } 
                }
                if (!checkLengthInArray(arrayError)) {
                    return true;
                }
            }
            return false;
        },
        
        //Check input is float more than zero in array
        //Parameter: array have contains element id  
        checkInputIsFloatMoreThanZeroInArray: function(arrayElementId) {
            //Check if array element id length = 0. return false
            if (checkLengthInArray(arrayElementId)) {
                var arrayError = [];
                for (var index = 0; index < arrayElementId.length; index++) {
                    //Check is null or empty
                    if (!(isNullOrEmpty($("$" + arrayElementId[index]).val()))) {
                        //Check input less than 0 and not is numeric
                        if (parseInt($("$" + arrayElementId[index]).val()) < 0 || !($.isNumeric($("$" + arrayElementId[index]).val()))) {
                            arrayError.push(arrayElementId[index]);
                        }
                    }
                }
                if (!checkLengthInArray(arrayError)) {
                    return true;
                }
            }
            return false;
        },
        
        //Add error in function check date 
        AddErrorInCheckDate: function(errorElementId) {
            $("#" + errorElementId).css("visibility", "visible");
            $("#" + errorElementId).text($("#"+errorElementId).attr('textLbl')  + "が不正です。");
            $("#" + errorElementId).addClass("input-validation-error-date");
           
            //$("#validateSummary").append('<li>' + $("#"+errorElementId).attr('textLbl') + '</li>');
        },
        
        //Check required for textbox
        //Add error in function check textbox required
        AddErrorInCheckRequiredTextbox: function(errorElementId) {
            $("#" + errorElementId).css("visibility", "visible");
            
            $("#" + errorElementId).text($("#"+errorElementId).attr('textLbl')  + "を入力してください。");
            $("#" + errorElementId).addClass("input-validation-error-date");
           
            //$("#validateSummary").append('<li>' + $("#"+errorElementId).attr('textLbl') + '</li>');
        },
        
         //Add error in function check textbox required
        AddErrorInCheckValidateTextbox: function(errorElementId) {
            $("#" + errorElementId).css("visibility", "visible");
            
            $("#" + errorElementId).text($("#"+errorElementId).attr('textLbl')  + "は数字で入力してください。");
            $("#" + errorElementId).addClass("input-validation-error-date");
           
            //$("#validateSummary").append('<li>' + $("#"+errorElementId).attr('textLbl') + '</li>');
        },
        
           //Add error in function check textbox required
        AddErrorInCheckRequiredCombobox: function(errorElementId) {
            $("#" + errorElementId).css("visibility", "visible");
            
            $("#" + errorElementId).text($("#"+errorElementId).attr('textLbl')  + "を入力してください。");
            $("#" + errorElementId).addClass("input-validation-error-date");
           
            //$("#validateSummary").append('<li>' + $("#"+errorElementId).attr('textLbl') + '</li>');
        },
        
        //Get and set year of selection
        InputYearWithSelected: function(selectBoxElementId, elementYearId, elementMonthId, elementDayId) {
            var errorElementId = "errorInDateTime";
            $("#"+errorElementId).css("visibility", "hidden");
            $("#"+errorElementId).text("");
            var year = 0;
            
            //Check if select box is not selected and year not input and month not input and day not input then return 1 -> true
            if ($("#" + selectBoxElementId).val() == 0 && $.trim($("#" + elementYearId).val()) == "" &&
                $.trim($("#" + elementMonthId).val()) == "" && $.trim($("#" + elementDayId).val()) == "") {
                return 1;
            }
            
            //Check if select box and all input year,month,day is not empty then calculate year
            if ($("#" + selectBoxElementId).val() != 0 && $.trim($("#" + elementYearId).val()) != "" &&
                $.trim($("#" + elementMonthId).val()) != "" && $.trim($("#" + elementDayId).val()) != "") {
                try {
                    var year = 1;
                    var month = parseInt($("#" + elementMonthId).val());
                    var day = parseInt($("#" + elementDayId).val());
                    if (month == 0 && day == 0) {
                        if ($("#" + selectBoxElementId).val() == "1") {
                            year = (parseInt($("#" + elementYearId).val()) - 1) + 1989;
                        }
                        if ($("#" + selectBoxElementId).val() == "2") {
                            year = (parseInt($("#" + elementYearId).val()) - 1) + 1926;
                        }
                        if ($("#" + selectBoxElementId).val() == "3") {
                            year = (parseInt($("#" + elementYearId).val()) - 1) + 1912;
                        }
                        if ($("#" + selectBoxElementId).val() == "4") {
                            year = (parseInt($("#" + elementYearId).val()) - 1) + 1868;
                        }
                        return year;
                    }
                } catch(e) {

                }
            }
            
            if ($("#" + selectBoxElementId).val() == 0) {
                 Helpers.AddErrorInCheckDate(errorElementId);
                return 0;
            }
            
            if($.isNumeric($("#" + elementYearId).val()) && $.isNumeric($("#" + elementMonthId).val()) && $.isNumeric($("#" + elementDayId).val()))
                {
                    //If selectbox have value '1' then year plus 1988
                    if ($("#" + selectBoxElementId).val() == "1") {
                        if (parseInt($("#" + elementYearId).val()) <= 1 && 
                            parseInt($("#" + elementMonthId).val()) == 1 && 
                            parseInt($("#" + elementDayId).val()) < 8) {
                            Helpers.AddErrorInCheckDate(errorElementId);
                            return 0;
                        }
                        year = (parseInt($("#" + elementYearId).val()) - 1) + 1989;
                    }
            
                    //If selectbox have value '2' 
                    else if ($("#"+selectBoxElementId).val() == "2") {
                         if (parseInt($("#" + elementYearId).val()) <= 1 && 
                            parseInt($("#" + elementMonthId).val()) <= 12 && 
                            parseInt($("#" + elementDayId).val()) < 24) {
                                Helpers.AddErrorInCheckDate(errorElementId);
                                return 0;
                        }
                        year = (parseInt($("#"+elementYearId).val()) - 1) + 1926;
                        if (year > 1989) {
                             Helpers.AddErrorInCheckDate(errorElementId);
                            return 0;                            
                        }
                        //Check if more than type year
                        if (year == 1989) {
                            if (parseInt($("#" + elementMonthId).val()) >= 1) {
                                if (parseInt($("#" + elementDayId).val()) >= 8) {
                                     Helpers.AddErrorInCheckDate(errorElementId);
                                    return 0;
                                }
                            }
                        }
                    } 
            
                    //If selectbox have value '3' and year between 1 and 15 then year plus 1911
                    else if ($("#" + selectBoxElementId).val() == "3") {
                        if (parseInt($("#" + elementYearId).val()) <= 1 && 
                            parseInt($("#" + elementMonthId).val()) <= 7 && 
                            parseInt($("#" + elementDayId).val()) < 29) {
                            Helpers.AddErrorInCheckDate(errorElementId);
                            return 0;
                        }
                        year = (parseInt($("#"+elementYearId).val()) - 1) + 1912;
                        if (year == 1926) {
                              Helpers.AddErrorInCheckDate(errorElementId);
                                    return 0;
                        }
                        //Check if more than type year
                        if (year == 1926) {
                            if (parseInt($("#" + elementMonthId).val()) >= 12) {
                                if (parseInt($("#" + elementDayId).val()) >= 25) {
                                    Helpers.AddErrorInCheckDate(errorElementId);
                                    return 0;
                                }
                            }
                        }
                    } 
            
                    //If selectbox have value '4' and year between 1 and 45 then year plus 1867
                    else if ($("#"+selectBoxElementId).val() == "4") {
                        if (parseInt($("#" + elementYearId).val()) <= 1 && 
                            parseInt($("#" + elementMonthId).val()) <=9 && 
                            parseInt($("#" + elementDayId).val()) < 7) {
                            Helpers.AddErrorInCheckDate(errorElementId);
                            return 0;
                        }
                        year = (parseInt($("#"+elementYearId).val()) - 1) + 1868;
                        if (year == 1912) {
                             Helpers.AddErrorInCheckDate(errorElementId);
                                    return 0;
                        }
                        //Check if more than type year
                        if (year == 1912) {
                            if (parseInt($("#" + elementMonthId).val()) >= 7) {
                                if (parseInt($("#" + elementDayId).val()) >= 30) {
                                     Helpers.AddErrorInCheckDate(errorElementId);
                                    return 0;
                                }
                            }
                        }
                    }
                    if (!Helpers.checkInputIsDate($("#" + elementYearId).val(), $("#" + elementMonthId).val(), $("#" + elementDayId).val())) {
                                Helpers.AddErrorInCheckDate(errorElementId);
                                return 0;
                    }
                    if (year == 0) {
                       Helpers.AddErrorInCheckDate(errorElementId);
                    }
                    return year;
                }
            if (parseInt($("#" + elementYearId).val()).toString() == "NaN" || !Helpers.isNullOrEmpty($("#" + elementMonthId).val()) || !Helpers.isNullOrEmpty($("#" + elementDayId).val())) {
                Helpers.AddErrorInCheckDate(errorElementId);
                
                return 0;
            }
           Helpers.AddErrorInCheckDate(errorElementId);
            return 0;
        },
        
        //Get and set year of selection is required
        InputYearWithSelectedRequired: function(selectBoxElementId, elementYearId, elementMonthId, elementDayId) {
            
            var errorElementId = "errorInDateTime";
            $("#"+errorElementId).css("visibility", "hidden");
            $("#"+errorElementId).text("");
            var year = 0;
            
            if ($("#" + selectBoxElementId).val() != 0 && $.trim($("#" + elementYearId).val()) != "" &&
                $.trim($("#" + elementMonthId).val()) != "" && $.trim($("#" + elementDayId).val()) != "") {
                try {
                    var yearInput = 1;
                    var month = parseInt($("#" + elementMonthId).val());
                    var day = parseInt($("#" + elementDayId).val());
                    if (month == 0 && day == 0) {
                        if ($("#" + selectBoxElementId).val() == "1") {
                            yearInput = (parseInt($("#" + elementYearId).val()) - 1) + 1989;
                        }
                        if ($("#" + selectBoxElementId).val() == "2") {
                            yearInput = (parseInt($("#" + elementYearId).val()) - 1) + 1926;
                        }
                        if ($("#" + selectBoxElementId).val() == "3") {
                            yearInput = (parseInt($("#" + elementYearId).val()) - 1) + 1912;
                        }
                        if ($("#" + selectBoxElementId).val() == "4") {
                            yearInput = (parseInt($("#" + elementYearId).val()) - 1) + 1868;
                        }
                        return yearInput;
                    }
                } catch(e) {

                }
            }

            if($.isNumeric($("#" + elementYearId).val()) && $.isNumeric($("#" + elementMonthId).val()) && $.isNumeric($("#" + elementDayId).val()))
                {
                    //If selectbox have value '1' then year plus 1988
                    if ($("#" + selectBoxElementId).val() == "1") {
                        if (parseInt($("#" + elementYearId).val()) <= 1 && 
                            parseInt($("#" + elementMonthId).val()) == 1 && 
                            parseInt($("#" + elementDayId).val()) < 8) {
                            Helpers.AddErrorInCheckDate(errorElementId);
                            return 0;
                        }
                        year = (parseInt($("#" + elementYearId).val()) - 1) + 1989;
                    }
            
                    //If selectbox have value '2' 
                    else if ($("#"+selectBoxElementId).val() == "2") {
                         if (parseInt($("#" + elementYearId).val()) <= 1 && 
                            parseInt($("#" + elementMonthId).val()) <= 12 && 
                            parseInt($("#" + elementDayId).val()) < 24) {
                                Helpers.AddErrorInCheckDate(errorElementId);
                                return 0;
                        }
                        year = (parseInt($("#"+elementYearId).val()) - 1) + 1926;
                        if (year > 1989) {
                             Helpers.AddErrorInCheckDate(errorElementId);
                            return 0;                            
                        }
                        //Check if more than type year
                        if (year == 1989) {
                            if (parseInt($("#" + elementMonthId).val()) >= 1) {
                                if (parseInt($("#" + elementDayId).val()) >= 8) {
                                     Helpers.AddErrorInCheckDate(errorElementId);
                                    return 0;
                                }
                            }
                        }
                    } 
            
                    //If selectbox have value '3' and year between 1 and 15 then year plus 1911
                    else if ($("#" + selectBoxElementId).val() == "3") {
                        if (parseInt($("#" + elementYearId).val()) <= 1 && 
                            parseInt($("#" + elementMonthId).val()) <= 7 && 
                            parseInt($("#" + elementDayId).val()) < 29) {
                            Helpers.AddErrorInCheckDate(errorElementId);
                            return 0;
                        }
                        year = (parseInt($("#"+elementYearId).val()) - 1) + 1912;
                        if (year == 1926) {
                              Helpers.AddErrorInCheckDate(errorElementId);
                                    return 0;
                        }
                        //Check if more than type year
                        if (year == 1926) {
                            if (parseInt($("#" + elementMonthId).val()) >= 12) {
                                if (parseInt($("#" + elementDayId).val()) >= 25) {
                                    Helpers.AddErrorInCheckDate(errorElementId);
                                    return 0;
                                }
                            }
                        }
                    } 
            
                    //If selectbox have value '4' and year between 1 and 45 then year plus 1867
                    else if ($("#"+selectBoxElementId).val() == "4") {
                        if (parseInt($("#" + elementYearId).val()) <= 1 && 
                            parseInt($("#" + elementMonthId).val()) <=9 && 
                            parseInt($("#" + elementDayId).val()) < 7) {
                            Helpers.AddErrorInCheckDate(errorElementId);
                            return 0;
                        }
                        year = (parseInt($("#"+elementYearId).val()) - 1) + 1868;
                        if (year == 1912) {
                             Helpers.AddErrorInCheckDate(errorElementId);
                                    return 0;
                        }
                        //Check if more than type year
                        if (year == 1912) {
                            if (parseInt($("#" + elementMonthId).val()) >= 7) {
                                if (parseInt($("#" + elementDayId).val()) >= 30) {
                                     Helpers.AddErrorInCheckDate(errorElementId);
                                    return 0;
                                }
                            }
                        }
                    }
                    if (!Helpers.checkInputIsDate($("#" + elementYearId).val(), $("#" + elementMonthId).val(), $("#" + elementDayId).val())) {
                                Helpers.AddErrorInCheckDate(errorElementId);
                                return 0;
                    }
                    if (year == 0) {
                       Helpers.AddErrorInCheckDate(errorElementId);
                    }
                    return year;
                }
            if (parseInt($("#" + elementYearId).val()).toString() == "NaN" || !Helpers.isNullOrEmpty($("#" + elementMonthId).val()) || !Helpers.isNullOrEmpty($("#" + elementDayId).val())) {
                Helpers.AddErrorInCheckDate(errorElementId);
                
                return 0;
            }
           Helpers.AddErrorInCheckDate(errorElementId);
            return 0;
        },
        
        //Get and set year of selection
        InputYearWithSelectedHasElementId: function(selectBoxElementId, elementYearId, elementMonthId, elementDayId, errorElementId) {
            $("#" + errorElementId).css("visibility", "hidden");
            $("#" + errorElementId).text("");
            
            if ($("#" + selectBoxElementId).val() == 0 && $.trim($("#" + elementYearId).val()) == "" &&
                $.trim($("#" + elementMonthId).val()) == "" && $.trim($("#" + elementDayId).val()) == "") {
                return 1;
            }
            
            if ($("#" + selectBoxElementId).val() != 0 && $.trim($("#" + elementYearId).val()) != "" &&
                $.trim($("#" + elementMonthId).val()) != "" && $.trim($("#" + elementDayId).val()) != "") {
                try {
                    var yearInput = 1;
                    var month = parseInt($("#" + elementMonthId).val());
                    var day = parseInt($("#" + elementDayId).val());
                    if (month == 0 && day == 0) {
                        if ($("#" + selectBoxElementId).val() == "1") {
                            yearInput = (parseInt($("#" + elementYearId).val()) - 1) + 1989;
                        }
                        if ($("#" + selectBoxElementId).val() == "2") {
                            yearInput = (parseInt($("#" + elementYearId).val()) - 1) + 1926;
                        }
                        if ($("#" + selectBoxElementId).val() == "3") {
                            yearInput = (parseInt($("#" + elementYearId).val()) - 1) + 1912;
                        }
                        if ($("#" + selectBoxElementId).val() == "4") {
                            yearInput = (parseInt($("#" + elementYearId).val()) - 1) + 1868;
                        }
                        return yearInput;
                    }
                } catch(e) {

                }
            }
            
            if ($("#" + selectBoxElementId).val() == 0) {
                            Helpers.AddErrorInCheckDate(errorElementId);
                    return 0;
                }
            var year = 0;
            if($.isNumeric($("#" + elementYearId).val()) && $.isNumeric($("#" + elementMonthId).val()) && $.isNumeric($("#" + elementDayId).val()))
                {
                    //If selectbox have value '1' then year plus 1988
                    if ($("#" + selectBoxElementId).val() == "1") {
                        if (parseInt($("#" + elementYearId).val()) <= 1 && 
                            parseInt($("#" + elementMonthId).val()) == 1 && 
                            parseInt($("#" + elementDayId).val()) < 8) {
                            Helpers.AddErrorInCheckDate(errorElementId);
                            return 0;
                        }
                        year = (parseInt($("#" + elementYearId).val()) - 1) + 1989;
                    }
            
                    //If selectbox have value '2' 
                    else if ($("#"+selectBoxElementId).val() == "2") {
                         if (parseInt($("#" + elementYearId).val()) <= 1 && 
                            parseInt($("#" + elementMonthId).val()) <= 12 && 
                            parseInt($("#" + elementDayId).val()) < 24) {
                                Helpers.AddErrorInCheckDate(errorElementId);
                                return 0;
                        }
                        year = (parseInt($("#"+elementYearId).val()) - 1) + 1926;
                        if (year > 1989) {
                             Helpers.AddErrorInCheckDate(errorElementId);
                            return 0;                            
                        }
                        //Check if more than type year
                        if (year == 1989) {
                            if (parseInt($("#" + elementMonthId).val()) >= 1) {
                                if (parseInt($("#" + elementDayId).val()) >= 8) {
                                     Helpers.AddErrorInCheckDate(errorElementId);
                                    return 0;
                                }
                            }
                        }
                    } 
            
                    //If selectbox have value '3' and year between 1 and 15 then year plus 1911
                    else if ($("#" + selectBoxElementId).val() == "3") {
                        if (parseInt($("#" + elementYearId).val()) <= 1 && 
                            parseInt($("#" + elementMonthId).val()) <= 7 && 
                            parseInt($("#" + elementDayId).val()) < 29) {
                            Helpers.AddErrorInCheckDate(errorElementId);
                            return 0;
                        }
                        year = (parseInt($("#"+elementYearId).val()) - 1) + 1912;
                        if (year == 1926) {
                              Helpers.AddErrorInCheckDate(errorElementId);
                                    return 0;
                        }
                        //Check if more than type year
                        if (year == 1926) {
                            if (parseInt($("#" + elementMonthId).val()) >= 12) {
                                if (parseInt($("#" + elementDayId).val()) >= 25) {
                                    Helpers.AddErrorInCheckDate(errorElementId);
                                    return 0;
                                }
                            }
                        }
                    } 
            
                    //If selectbox have value '4' and year between 1 and 45 then year plus 1867
                    else if ($("#"+selectBoxElementId).val() == "4") {
                        if (parseInt($("#" + elementYearId).val()) <= 1 && 
                            parseInt($("#" + elementMonthId).val()) <=9 && 
                            parseInt($("#" + elementDayId).val()) < 7) {
                            Helpers.AddErrorInCheckDate(errorElementId);
                            return 0;
                        }
                        year = (parseInt($("#"+elementYearId).val()) - 1) + 1868;
                        if (year == 1912) {
                             Helpers.AddErrorInCheckDate(errorElementId);
                                    return 0;
                        }
                        //Check if more than type year
                        if (year == 1912) {
                            if (parseInt($("#" + elementMonthId).val()) >= 7) {
                                if (parseInt($("#" + elementDayId).val()) >= 30) {
                                     Helpers.AddErrorInCheckDate(errorElementId);
                                    return 0;
                                }
                            }
                        }
                    }
                    if (!Helpers.checkInputIsDate($("#" + elementYearId).val(), $("#" + elementMonthId).val(), $("#" + elementDayId).val())) {
                         Helpers.AddErrorInCheckDate(errorElementId);
                                return 0;
                    }
                
                    return year;
                }
            if (parseInt($("#" + elementYearId).val()).toString() == "NaN" || !Helpers.isNullOrEmpty($("#" + elementMonthId).val()) || !Helpers.isNullOrEmpty($("#" + elementDayId).val())) {
                Helpers.AddErrorInCheckDate(errorElementId);
                return 0;
            }
            Helpers.AddErrorInCheckDate(errorElementId);
            return 0;
        },
        
        //Required TextBox
        TextBoxRequired: function(textboxId,errorElementId) {
             $("#" + errorElementId).css("visibility", "hidden");
            $("#" + errorElementId).text("");
            if ($("#"+textboxId).val()=="") {
                Helpers.AddErrorInCheckRequiredTextbox(errorElementId);
                return null;
            }
            return $("#" + textboxId).val();
        },
        
         //Required TextBox
        TextBoxValidateCheck: function(textboxId,errorElementId) {
             $("#" + errorElementId).css("visibility", "hidden");
            $("#" + errorElementId).text("");
            if ($("#" + textboxId).val() == "") {
                Helpers.AddErrorInCheckRequiredTextbox(errorElementId);
                return null;
            } 
            else {
                  var pattern=/^\d{1,5}(\.\d{1,3})?$/;
                if (pattern.test($("#" + textboxId).val())) {
                   return $("#" + textboxId).val();
                }
                 Helpers.AddErrorInCheckValidateTextbox(errorElementId);
                        return null;  
                  
            }
           // return $("#" + textboxId).val();
        },
        
         //Required Combobox
        ComboboxRequired: function(comboboxId,errorElementId) {
             $("#" + errorElementId).css("visibility", "hidden");
            $("#" + errorElementId).text("");
            if ($("#"+comboboxId).val()==0) {
                Helpers.AddErrorInCheckRequiredTextbox(errorElementId);
                return null;
            }
            return $("#" + comboboxId).val();
        },

        //Get and set year of selection Required
        InputYearWithSelectedHasElementIdRequired: function(selectBoxElementId, elementYearId, elementMonthId, elementDayId, errorElementId) {
            $("#" + errorElementId).css("visibility", "hidden");
            $("#" + errorElementId).text("");
            if ($("#" + selectBoxElementId).val() == "0") {
                Helpers.AddErrorInCheckDate(errorElementId);
                return 0;
            }
            var year = 0;
            
            if ($("#" + selectBoxElementId).val() != 0 && $.trim($("#" + elementYearId).val()) != "" &&
                $.trim($("#" + elementMonthId).val()) != "" && $.trim($("#" + elementDayId).val()) != "") {
                try {
                    var yearInput = 1;
                    var month = parseInt($("#" + elementMonthId).val());
                    var day = parseInt($("#" + elementDayId).val());
                    if (month == 0 && day == 0) {
                        if ($("#" + selectBoxElementId).val() == "1") {
                            yearInput = (parseInt($("#" + elementYearId).val()) - 1) + 1989;
                        }
                        if ($("#" + selectBoxElementId).val() == "2") {
                            yearInput = (parseInt($("#" + elementYearId).val()) - 1) + 1926;
                        }
                        if ($("#" + selectBoxElementId).val() == "3") {
                            yearInput = (parseInt($("#" + elementYearId).val()) - 1) + 1912;
                        }
                        if ($("#" + selectBoxElementId).val() == "4") {
                            yearInput = (parseInt($("#" + elementYearId).val()) - 1) + 1868;
                        }
                        return yearInput;
                    }
                } catch(e) {

                }
            }

            if($.isNumeric($("#" + elementYearId).val()) && $.isNumeric($("#" + elementMonthId).val()) && $.isNumeric($("#" + elementDayId).val()))
                {
                    //If selectbox have value '1' then year plus 1988
                    if ($("#" + selectBoxElementId).val() == "1") {
                        if (parseInt($("#" + elementYearId).val()) <= 1 && 
                            parseInt($("#" + elementMonthId).val()) == 1 && 
                            parseInt($("#" + elementDayId).val()) < 8) {
                            Helpers.AddErrorInCheckDate(errorElementId);
                            return 0;
                        }
                        year = (parseInt($("#" + elementYearId).val()) - 1) + 1989;
                    }
            
                    //If selectbox have value '2' 
                    else if ($("#"+selectBoxElementId).val() == "2") {
                         if (parseInt($("#" + elementYearId).val()) <= 1 && 
                            parseInt($("#" + elementMonthId).val()) <= 12 && 
                            parseInt($("#" + elementDayId).val()) < 24) {
                                Helpers.AddErrorInCheckDate(errorElementId);
                                return 0;
                        }
                        year = (parseInt($("#"+elementYearId).val()) - 1) + 1926;
                        if (year > 1989) {
                             Helpers.AddErrorInCheckDate(errorElementId);
                            return 0;                            
                        }
                        //Check if more than type year
                        if (year == 1989) {
                            if (parseInt($("#" + elementMonthId).val()) >= 1) {
                                if (parseInt($("#" + elementDayId).val()) >= 8) {
                                     Helpers.AddErrorInCheckDate(errorElementId);
                                    return 0;
                                }
                            }
                        }
                    } 
            
                    //If selectbox have value '3' and year between 1 and 15 then year plus 1911
                    else if ($("#" + selectBoxElementId).val() == "3") {
                        if (parseInt($("#" + elementYearId).val()) <= 1 && 
                            parseInt($("#" + elementMonthId).val()) <= 7 && 
                            parseInt($("#" + elementDayId).val()) < 29) {
                            Helpers.AddErrorInCheckDate(errorElementId);
                            return 0;
                        }
                        year = (parseInt($("#"+elementYearId).val()) - 1) + 1912;
                        if (year == 1926) {
                              Helpers.AddErrorInCheckDate(errorElementId);
                                    return 0;
                        }
                        //Check if more than type year
                        if (year == 1926) {
                            if (parseInt($("#" + elementMonthId).val()) >= 12) {
                                if (parseInt($("#" + elementDayId).val()) >= 25) {
                                    Helpers.AddErrorInCheckDate(errorElementId);
                                    return 0;
                                }
                            }
                        }
                    } 
            
                    //If selectbox have value '4' and year between 1 and 45 then year plus 1867
                    else if ($("#"+selectBoxElementId).val() == "4") {
                        if (parseInt($("#" + elementYearId).val()) <= 1 && 
                            parseInt($("#" + elementMonthId).val()) <=9 && 
                            parseInt($("#" + elementDayId).val()) < 7) {
                            Helpers.AddErrorInCheckDate(errorElementId);
                            return 0;
                        }
                        year = (parseInt($("#"+elementYearId).val()) - 1) + 1868;
                        if (year == 1912) {
                             Helpers.AddErrorInCheckDate(errorElementId);
                                    return 0;
                        }
                        //Check if more than type year
                        if (year == 1912) {
                            if (parseInt($("#" + elementMonthId).val()) >= 7) {
                                if (parseInt($("#" + elementDayId).val()) >= 30) {
                                     Helpers.AddErrorInCheckDate(errorElementId);
                                    return 0;
                                }
                            }
                        }
                    }
                    if (!Helpers.checkInputIsDate($("#" + elementYearId).val(), $("#" + elementMonthId).val(), $("#" + elementDayId).val())) {
                         Helpers.AddErrorInCheckDate(errorElementId);
                                return 0;
                    }
                
                    return year;
                }
            if (parseInt($("#" + elementYearId).val()).toString() == "NaN" || !Helpers.isNullOrEmpty($("#" + elementMonthId).val()) || !Helpers.isNullOrEmpty($("#" + elementDayId).val())) {
                Helpers.AddErrorInCheckDate(errorElementId);
                return 0;
            }
            Helpers.AddErrorInCheckDate(errorElementId);
            return 0;
        },
        
        //Get and set year of selection but not exist month day
        InputYearWithSelectButNotExistMonthAndDayReturnYear: function(selectBoxElementId, elementYearId, elementIdError) {
            if ($("#" + selectBoxElementId).val() == 0 && $.trim($("#" + elementYearId).val()) == "") {
                return 1;
            }
            var yearNumber = $("#" + elementYearId).val();
            var typeYear = $("#" + selectBoxElementId).val();
            var errorElementId = elementIdError;
            $("#"+errorElementId).css("visibility", "hidden");
            $("#"+errorElementId).text("");
            var year = 0;

            if($.isNumeric(yearNumber))
                {
                    //If selectbox have value '1' then year plus 1988
                    if (typeYear == "1") {
                        year = (parseInt(yearNumber) - 1) + 1989;
                    }
            
                    //If selectbox have value '2' 
                    else if (typeYear == "2") {
                        year = (parseInt(yearNumber) - 1) + 1926;
                        if (year >= 1989) {
                            Helpers.AddErrorInCheckDate(errorElementId);
                            return 0;                            
                        }
                    } 
            
                    //If selectbox have value '3' and year between 1 and 15 then year plus 1911
                    else if (typeYear == "3") {
                        year = (parseInt(yearNumber) - 1) + 1912;
                        if (year >= 1926) {
                              Helpers.AddErrorInCheckDate(errorElementId);
                              return 0;
                        }
                    } 
            
                    //If selectbox have value '4' and year between 1 and 45 then year plus 1867
                    else if (typeYear == "4") {
                        year = (parseInt(yearNumber) - 1) + 1868;
                        if (year >= 1912) {
                             Helpers.AddErrorInCheckDate(errorElementId);
                             return 0;
                        }
                    }
                    if (year == 0) {
                        Helpers.AddErrorInCheckDate(errorElementId);
                    }
                    return year;
                }
            if (parseInt(yearNumber).toString() == "NaN" ) {
                Helpers.AddErrorInCheckDate(errorElementId);
                return 0;
            }
            return 0;
        },
        
        //Get and set year of selection but not exist month day
        InputYearWithSelectButNotExistMonthAndDayReturnYearRequied: function(selectBoxElementId, elementYearId, elementIdError) {
            
            var yearNumber = $("#" + elementYearId).val();
            var typeYear = $("#" + selectBoxElementId).val();
            var errorElementId = elementIdError;
            $("#"+errorElementId).css("visibility", "hidden");
            $("#"+errorElementId).text("");
            var year = 0;
            
            if($.isNumeric(yearNumber))
                {
                    //If selectbox have value '1' then year plus 1988
                    if (typeYear == "1") {
                        year = (parseInt(yearNumber) - 1) + 1989;
                    }
            
                    //If selectbox have value '2' 
                    else if (typeYear == "2") {
                        year = (parseInt(yearNumber) - 1) + 1926;
                        if (year >= 1989) {
                            Helpers.AddErrorInCheckDate(errorElementId);
                            return 0;                            
                        }
                    } 
            
                    //If selectbox have value '3' and year between 1 and 15 then year plus 1911
                    else if (typeYear == "3") {
                        year = (parseInt(yearNumber) - 1) + 1912;
                        if (year >= 1926) {
                              Helpers.AddErrorInCheckDate(errorElementId);
                              return 0;
                        }
                    } 
            
                    //If selectbox have value '4' and year between 1 and 45 then year plus 1867
                    else if (typeYear == "4") {
                        year = (parseInt(yearNumber) - 1) + 1868;
                        if (year >= 1912) {
                             Helpers.AddErrorInCheckDate(errorElementId);
                             return 0;
                        }
                    }
                    if (year == 0) {
                        Helpers.AddErrorInCheckDate(errorElementId);
                    }
                    return year;
                }
            if (parseInt(yearNumber).toString() == "NaN" ) {
                Helpers.AddErrorInCheckDate(errorElementId);
                return 0;
            }
            return 0;
        },

        //Get and set year of selection but not exist month day
        InputYearWithSelectButNotExistMonthAndDay: function(selectBoxElementId, elementYearId, elementIdError) {
             if ($("#" + selectBoxElementId).val() == 0 && $.trim($("#" + elementYearId).val()) == "") {
                return null;
            }
            var yearNumber = $("#" + elementYearId).val();
            var typeYear = $("#" + selectBoxElementId).val();
            var errorElementId = elementIdError;
            $("#"+errorElementId).css("visibility", "hidden");
            var year = 0;
            
            if($.isNumeric(yearNumber))
                {
                if (typeYear == 0) {
                            Helpers.AddErrorInCheckDate(errorElementId);
                    return 0;
                }
                //If selectbox have value '1' then year plus 1988
                    if (typeYear == "1") {
                        year = (parseInt(yearNumber) - 1) + 1989;
                    }
            
                    //If selectbox have value '2' 
                    else if (typeYear == "2") {
                        year = (parseInt(yearNumber) - 1) + 1926;
                        if (year >= 1989) {
                            Helpers.AddErrorInCheckDate(errorElementId);
                            return 0;                            
                        }
                    } 
            
                    //If selectbox have value '3' and year between 1 and 15 then year plus 1911
                    else if (typeYear == "3") {
                        year = (parseInt(yearNumber) - 1) + 1912;
                        if (year >= 1926) {
                              Helpers.AddErrorInCheckDate(errorElementId);
                              return 0;
                        }
                    } 
            
                    //If selectbox have value '4' and year between 1 and 45 then year plus 1867
                    else if (typeYear == "4") {
                        year = (parseInt(yearNumber) - 1) + 1868;
                        if (year >= 1912) {
                             Helpers.AddErrorInCheckDate(errorElementId);
                             return 0;
                        }
                    }
                    return yearNumber;
                }
            if (parseInt(yearNumber).toString() == "NaN" ) {
                Helpers.AddErrorInCheckDate(errorElementId);
                return 0;
            }
            Helpers.AddErrorInCheckDate(errorElementId);
            return 0;
        },
        
        //Get and set year of selection but not exist month day
        InputYearWithSelectButNotExistMonthAndDayRequired: function(selectBoxElementId, elementYearId, elementIdError) {
            
            var yearNumber = $("#" + elementYearId).val();
            var typeYear = $("#" + selectBoxElementId).val();
            var errorElementId = elementIdError;
            $("#"+errorElementId).css("visibility", "hidden");
            var year = 0;
            
            if($.isNumeric(yearNumber))
                {
                if (typeYear == 0) {
                            Helpers.AddErrorInCheckDate(errorElementId);
                    return 0;
                }
                //If selectbox have value '1' then year plus 1988
                    if (typeYear == "1") {
                        year = (parseInt(yearNumber) - 1) + 1989;
                    }
            
                    //If selectbox have value '2' 
                    else if (typeYear == "2") {
                        year = (parseInt(yearNumber) - 1) + 1926;
                        if (year >= 1989) {
                            Helpers.AddErrorInCheckDate(errorElementId);
                            return 0;                            
                        }
                    } 
            
                    //If selectbox have value '3' and year between 1 and 15 then year plus 1911
                    else if (typeYear == "3") {
                        year = (parseInt(yearNumber) - 1) + 1912;
                        if (year >= 1926) {
                              Helpers.AddErrorInCheckDate(errorElementId);
                              return 0;
                        }
                    } 
            
                    //If selectbox have value '4' and year between 1 and 45 then year plus 1867
                    else if (typeYear == "4") {
                        year = (parseInt(yearNumber) - 1) + 1868;
                        if (year >= 1912) {
                             Helpers.AddErrorInCheckDate(errorElementId);
                             return 0;
                        }
                    }
                    return yearNumber;
                }
            if (parseInt(yearNumber).toString() == "NaN" ) {
                Helpers.AddErrorInCheckDate(errorElementId);
                return 0;
            }
            Helpers.AddErrorInCheckDate(errorElementId);
            return 0;
        },

        //show message in link header
        showMessageInLinkHeader: function(mesage) {
        //Check if checkVersion is false is IE 
            if (checkVersion() == true) {
                var boolChange = false;
                $('.confirmation').on('click', function() {
                    
                    if ($("#flagChange").val() == "1") {
                        boolChange = true;
                    }
                    var elementHref = $(this).attr("href");
                    if (boolChange == false) {
                        window.location.href = elementHref;
                    } else {
                        event.returnValue = false;
                        Helpers.confirmation(mesage).then(function(answer) {
                            if (answer == "false") {
                                event.returnValue = false;
                            } else {
                                window.location.href = elementHref;
                            }
                        });
                    }
                    event.returnValue = false;
                });
                //if("#flagChange").change
                $('form :input').change(function() {
                    boolChange = true;
                });
                $('select').on('change', function() {
                    boolChange = true;
                });
                $('input :file').change(function() {
                    boolChange = true;
                });
            } 
            //is not IE
            else {                
                var boolChange = 0;
                $('form :input').change(function() {
                    boolChange++;                    
                });
                $('select').on('change', function() {
                    boolChange++;                    
                });
                $('input :file').change(function() {
                    boolChange++;                    
                });
                $('.confirmation').on('click', function(e) {
                    var elememt = $(this);
                    if ($.trim($("#flagChange").val()) == "1") {
                        boolChange++;                    
                    }
                    if (boolChange >= 1) {
                        e.preventDefault();
                        e.returnValue = false;
                        Helpers.confirmation(mesage).then(function (answer) {
                            if (answer == "false") {
                                e.preventDefault();
                                e.returnValue = false;
                            } else {
                                window.location.href = elememt.attr("href");
                            }
                        });
                    }
                    
                });                
            }
            
            $(".confirmation").each(function() {
                if ($(this).attr("class") == "confirmation active") {
                    $(this).prop( "disabled", true );
                    $(this).css("pointer-events", "none");
                }
                    
            });
        },
        
        showLargeImage: function(imagePath, containerDivId) {
            $('body').append('<div class="modal-overlay" style="height:' + (135 + $('#' + containerDivId).height()) + 
                'px; position: absolute; width: 100%; background-color: black; opacity: 0.6; top: 0px; left: 0px;">'+ 
                '</div><div id="modalImgId" class="modal-img"><img src="' +
                imagePath.replace("small", "large") + 
                '" style="height:500px; width:500px;  background-color: white; padding: 5px;" /></div>').addClass('noscroll');
           $('body').unbind("click");
           $('body').on('click', '.modal-overlay', function () {
                $('.modal-overlay, .modal-img').remove();
                $('body').removeClass('noscroll');
           });
            
            $('#modalImgId').animate({
                opacity: 1
            }, 1000);
            setPositionCenterFor("modalImgId");
        },
/*--------------------------------------------------------------------------------------
* End check
*----------------------------------------------------------------------------------------*/

        addErrorInToolTip: function (arrayElementName, errorMessage) {
            if (arrayElementName.length != 0) {
                for (var index = 0; index < arrayElementName.length; index++) {
                    $("#" + arrayElementName[index].toString() + "").attr("title", errorMessage);
                    $("#" + arrayElementName[index].toString() + "").addClass("error");
                }
            }
        },

        restoreTitle: function (arrayElementName) {
            for (var index = 0; index < arrayElementName.length; index++) {
                $("#" + arrayElementName[index].toString() + "").attr("title", "");
                $("#" + arrayElementName[index].toString() + "").removeClass("error");
            }
        },

        removeClassError: function (arrayRemoveClassError) {
            for (var index = 0; index < arrayRemoveClassError.length; index++) {
                var name = arrayRemoveClassError[index].split("Error", 1);
                $("#" + name.toString() + "").removeClass("error");
                $("#" + name.toString() + "").attr("title", "");
            }
        },

        isError: function (arrayElementName) {
            var count = 0;
            for (var index = 0; index < arrayElementName.length; index++) {
                if ($.trim($("#" + arrayElementName[index] + "").text()) != "") {
                    count++;
                }
            }
            if (count > 0) {
                return false;
            }
            return true;
        },

        addToolTip: function (arrayElementName) {
            for (var index = 0; index < arrayElementName.length; index++) {
                var nameError = arrayElementName[index];
                var name = arrayElementName[index].split("Error", 1);
                $("#" + name.toString() + "").attr("title", $("#" + nameError.toString() + "").text());
            }
        },

        isNumberFloatInput: function (elementName, errorMessageNumber, errorMessageLessThan) {
            var countError = 0;
            if ($("#" + elementName + "").val() != "") {
                if (parseInt($("#" + elementName + "").val()) < 0) {
                    $("#" + elementName + "").attr("title", errorMessageLessThan);
                    $("#" + elementName.toString() + "").addClass("error");
                    countError++;
                }
                if (!($.isNumeric($("#" + elementName + "").val()))) {
                    $("#" + elementName + "").attr("title", errorMessageNumber);
                    $("#" + elementName + "").addClass("error");
                    countError++;
                }
                
            }
            if (countError == 0)
                return true;
            return false;
        },

        isNumberFloat: function (arrayElementName, errorMessageNumber, errorMessageLessThan) {
            var countError = 0;
            for (var index = 0; index < arrayElementName.length; index++) {
                if ($("#" + arrayElementName[index] + "").val() != "") {

                    if (!($.isNumeric($("#" + arrayElementName[index] + "").val()))) {
                        $("#" + arrayElementName[index] + "").attr("title", errorMessageNumber);
                        $("#" + arrayElementName[index].toString() + "").addClass("error");
                        countError++;
                    }

                    if (parseInt($("#" + arrayElementName[index] + "").val()) < 0) {

                        $("#" + arrayElementName[index] + "").attr("title", errorMessageLessThan);
                        $("#" + arrayElementName[index].toString() + "").addClass("error");
                        countError++;
                    }
                }
            }
            if (countError == 0)
                return true;
            return false;
        },

        inputNumber: function (arrayElementName) {
            for (var index = 0; index < arrayElementName.length; index++) {
                $("#" + arrayElementName[index] + "").keydown(function (event) {
                    // Allow: backspace, delete, tab and escape
                    if (event.keyCode == 46 || event.keyCode == 8 || event.keyCode == 9 || event.keyCode == 27 ||
                        // Allow: Ctrl+A
                        (event.keyCode == 65 && event.ctrlKey === true) ||
                        // Allow: home, end, left, right
                        (event.keyCode >= 35 && event.keyCode <= 39)) {
                        // let it happen, don't do anything
                        return;
                    }
                    else {
                        // Ensure that it is a number and stop the keypress
                        if (event.shiftKey || (event.keyCode < 48 || event.keyCode > 57) && (event.keyCode < 96 || event.keyCode > 105)) {
                            event.preventDefault();
                        }
                    }
                });
            }
        },

        isNullOrEmptyInArray: function (arrayError, arrayMessageError) {
            var counter = 0;
            for (var index = 0; index < arrayError.length; index++) {
                if ($.trim($("#" + arrayError[index] + "").val()) == "") {
                    $("#" + arrayError[index] + "").attr("title", arrayMessageError);
                    $("#" + arrayError[index] + "").addClass("error");
                    counter++;
                }
            }
            if (counter > 0) {
                return false;
            } else {
                return true;
            }
        },

        isNumber: function (n) {
            if ($.trim(n) != "") {
                var temp = (!/[^0-9]/g.test(n));
                if (!temp) {
                    return false;
                }
            }
            return true;
        },
        
        isNumberInArrayZipCode: function (arrayElement) {
            var countError = 0;
            for (var index = 0; index < arrayElement.length; index++) {
                if ($.trim($("#" + arrayElement[index] + "").val()) != "") {
                    var temp = (!/[^0-9]/g.test($("#" + arrayElement[index] + "").val()));
                    if (!temp) {
                        countError++;
                    }
                }
            }
            if (countError >= 1) {
                return false;
            }
            return true;
        },

        isNumberInArray: function (arrayElement, errorMessage) {
            var countError = 0;
            for (var index = 0; index < arrayElement.length; index++) {
                if ($.trim($("#" + arrayElement[index] + "").val()) != "") {
                    var temp = (!/[^0-9]/g.test($("#" + arrayElement[index] + "").val()));
                    if (!temp) {
                        $("#" + arrayElement[index].toString() + "").attr("title", errorMessage);
                        $("#" + arrayElement[index].toString() + "").addClass("error");
                        countError++;
                    }
                }
            }
            if (countError > 0) {
                return false;
            }
            return true;
        },

        

        isValidEmailJapanese: function (emailValue) {
            if (!/[^A-Za-z0-9@A-Za-z.A-Za-z]/g.test($.trim(emailValue))) {
                return false;
            }
            return true;
        },
        
        testMailvalid: function (mailValue) {
            if (!Helpers.isNull(mailValue)) {
                if ($.trim(mailValue) != "") {
                    var temp = (/^[a-zA-Z0-9!-/:-@¥[-`{-~]+$/g.test(mailValue));
                    if (!temp) {
                        return false;
                    }
                }
            }
            return true;
        },

        isValidPasswordJapanese: function (passwordValue) {
            if (!Helpers.isNull(passwordValue)) {
                if ($.trim(passwordValue) != "") {
                    var temp = (/^[a-zA-Z0-9!-/:-@¥[-`{-~]+$/g.test(passwordValue));
                    if (!temp) {
                        return false;
                    }
                }
            }
            return true;
        },

        convertDate: function (dateValue) {
            var fromFormat = 'dd/MM/yyyy',
                toFormat = 'ddd, MMM dd yyyy';
        },

        //extend from an object
        extend: function (protobj, skipBaseConstructor) {
            protobj = protobj || {};
            var subClass = null;
            var baseConstructor = this;
            if (typeof (baseConstructor) != "function") {
                baseConstructor = this.init;
            }

            if (protobj.init) {
                subClass = function () {
                    if (!skipBaseConstructor) {
                        baseConstructor.apply(this, arguments);
                    }
                    protobj.init.apply(this, arguments);
                };
            } else {
                subClass = function () {
                    if (!skipBaseConstructor) {
                        baseConstructor.apply(this, arguments);
                    }
                };
                protobj.init = baseConstructor;
            }
            subClass.prototype = subClass.prototype || {};
            $.extend(true, subClass.prototype, this.prototype, protobj);
            subClass.extend = this.extend;
            return subClass;
        }
        
        
    };
    Helpers = new UtilityClass();

    
/*--------------------------------------------------------------------------------------
* Custom ajax request
*----------------------------------------------------------------------------------------*/

    //Core functions
    Helpers.AjaxCore = Helpers.extend({
        JSON: 'json',
        HTML: 'html',
        POST: 'POST',
        GET: 'GET',
        SLASH: '/',
        AND: '&',
        QUESTION_MARK: '?',

        //called when an ajax request is completed
        ajaxComplete: function () {
            if (this.mask) {
                $.unblockUI();
                this.mask = null;
            }
        },

        getRootUrl: function () {
            var rootUrl = Helpers.rootUrl;
            
            if (/\/.+/.test(rootUrl)) {
                rootUrl = rootUrl + this.SLASH;
            }

            return rootUrl;
        },

        //get url from controller, action
        buildUrl: function (module, controller, action) {
            var rootUrl = this.getRootUrl();
            var url = rootUrl + controller + this.SLASH + action;
            
            if (!Helpers.isNullOrEmpty(module)) {
                url = rootUrl + "m/" + module + this.SLASH + controller + this.SLASH + action;
            }

            return url;
        },

        checkError: function (response, jqXhr) {
            var result = null;

            if (typeof (response) == "string"
                && jqXhr.getResponseHeader("Content-Type") !== null
                && jqXhr.getResponseHeader("Content-Type") !== undefined
                && jqXhr.getResponseHeader("Content-Type").indexOf('application/json') >= 0) {
                result = eval('(' + response + ')');
            } else {
                result = response;
            }

            if (result) {
                if (Helpers.isNullOrEmpty(result.ErrorMessage) == false) {
                    this.showErrorMessage(result.ErrorMessage);
                }

                if (Helpers.isNullOrEmpty(result.Redirect) == false) {
                    this.ajaxComplete();
                    window.location = result.Redirect;
                    return true;
                }

                return false;
            }

            return false;
        },

        showErrorMessage: function (errorMessage) {
            alert(errorMessage);
        },

        //send ajax request
        ajax: function (options) {
            var url = options.url,
                dataType = (typeof options.dataType === 'undefined') ? this.JSON : options.dataType,
                contentType = (typeof options.contentType === 'undefined') ? "application/json" : options.contentType,
                async = (typeof options.async === 'undefined') ? true : options.async,
                cache = (typeof options.cache === 'undefined') ? false : options.cache,
                traditional = options.traditional == undefined ? false : options.traditional;

            if (!url) {
                url = this.buildUrl(options.module, options.controller, options.action);
            }

            if (options.showMask) {
                this.mask = {
                    css: { backgroundColor: 'transparent', border: 'none', zIndex: 10002},
                    message: '<div class="loadingPage">ローディング中</div>'
                };
                $.blockUI(this.mask);
            }

            $.ajax({
                url: url,
                data: options.data,
                dataType: dataType,
                type: options.type,
                cache: cache,
                async: async,
                traditional: traditional,
                context: this,
                contentType: contentType,
                success: function (result, textStatus, jqXhr) {
                    var isSuccessful = true;

                    if (result) {
                        if (this.checkError(result, jqXhr)) {
                            isSuccessful = false;
                        }
                    }

                    if (isSuccessful) {
                        try {
                            options.success.call(this, result);
                        } catch (error) {
                            this.showErrorMessage(error, error);
                        }
                    }

                    this.ajaxComplete();
                },
                error: function (jqXhr, textStatus, errorThrown) {
                    this.checkError(jqXhr.responseText, jqXhr);
                    this.ajaxComplete();
                }
            });

            return false;
        },
        
        //Show "loading" page
        showLoadingPage: function() {
            $.blockUI({
                css: { backgroundColor: 'transparent', border: 'none', zIndex: 10002},
                message: '<div class="loadingPage">ローディング中</div>'
            });
        },
        
        //Hide "loading" page
        hideLoadingPage: function() {
            $.unblockUI();
        },
        
        //Show "loading" print map
        showLoadingPrint: function() {
            $.blockUI({
                 css: { backgroundColor: '#fff', border: 'none', zIndex: 10002},
                 message:'<div class="dialog_loading loadingContent">ローディング中</div>'
            });
        },
        
        //send ajax request with data in JSON format and GET verb
        getJson: function (options) {
            var defaultOptions = { dataType: this.JSON, type: this.GET };
            var ajaxOptions = $.extend({}, defaultOptions, options);
            this.ajax(ajaxOptions);
        },

        //send ajax request with data in JSON format and POST verb
        postJson: function (options) {
            var defaultOptions = { dataType: this.JSON, type: this.POST };
            var ajaxOptions = $.extend({}, defaultOptions, options);
            this.ajax(ajaxOptions);
        },

        //send ajax request with data in HTML format and GET verb
        getHtml: function (options) {
            var defaultOptions = { dataType: this.HTML, type: this.GET };
            var ajaxOptions = $.extend({}, defaultOptions, options);
            this.ajax(ajaxOptions);
        },

        //send ajax request with data in HTML format and POST verb
        postHtml: function (options) {
            var defaultOptions = { dataType: this.HTML, type: this.POST };
            var ajaxOptions = $.extend({}, defaultOptions, options);
            this.ajax(ajaxOptions);
        },

        //navigate to a url built from controller, action
        redirectToAction: function (options) {
            var url = this.buildUrl(options.controller, options.action);
            if (options.params) {
                if (options.params.length > 1)
                    options.params.unshift(this.QUESTION_MARK);
                url = url + this.SLASH + options.params.join(this.AND);
            }
            window.location = url;
        }
    });

    Helpers.ajaxHelper = new Helpers.AjaxCore();

})(jQuery, window.rm = window.rm || {});

/*--------------------------------------------------------------------------------------
* Disable Back space keyboard
*----------------------------------------------------------------------------------------*/
//disable Backspace on page 
$(document).unbind('keydown').bind('keydown', function (event) {
    var doPrevent = false;
    if (event.keyCode === 8) {
        var d = event.srcElement || event.target;
        if ((d.tagName.toUpperCase() === 'INPUT' && (d.type.toUpperCase() === 'TEXT' || d.type.toUpperCase() === 'PASSWORD' || d.type.toUpperCase() === 'FILE'))
             || d.tagName.toUpperCase() === 'TEXTAREA') {
            doPrevent = d.readOnly || d.disabled;
        }
        else {
            doPrevent = true;
        }
    }

    if (doPrevent) {
        event.preventDefault();
    }
});

//Check input number 
var na = /^\d+(\.\d+)?$/;

//do not enter when input in form .
$(document).unbind('keydown').bind('keydown', function (event) {
    var doPrevent = false;
    if (event.keyCode === 13) {
        var d = event.srcElement || event.target;
        if ((d.tagName.toUpperCase() === 'INPUT' && (d.type.toUpperCase() === 'TEXT' || d.type.toUpperCase() === 'PASSWORD' || d.type.toUpperCase() === 'FILE'))) {
            doPrevent = true;
            //Check if element exist class ENDENTER then this element have enter key press
            if (d.className.toUpperCase() == "ENDENTER" || d.className.toUpperCase() == "ENDENTER VALID" ) {
                doPrevent = d.readOnly || d.disabled;
            }
        }
        else {            
            doPrevent = d.readOnly || d.disabled;
        }
    }

    if (doPrevent) {
        event.preventDefault();
    }
});

$(function() {
    try {
        //check if only permission read is 1 then user exist permission readonly
        //if user not exist permission write then disasble input, select and textarea
        if ($("#OnlyPermissionRead").val() == "1") {
            $("#main :input").not(".enableInclusivePermissionRead").prop("disabled", true);
            $("#main :select").not(".enableInclusivePermissionRead").prop("disabled", true);
            $("#main :textarea").not(".enableInclusivePermissionRead").prop("disabled", true);
        }
    } catch(ex) {
    }

    var counterError = 0;
    var arrayTextLbl = [];
    if ($('form .display-error :visible').length > 0) {
        $("form .display-error").each(function() {
            if ($(this).css("visibility") == "visible") {
                counterError++;
                if (!(Helpers.isNullOrEmpty($(this).attr("textLbl")))) {
                    arrayTextLbl.push($(this).attr("textLbl"));
                }
            }
        });
    }
    
    if (counterError != 0) {
        if (arrayTextLbl.length >= 1) {
            $("#validateSummary").empty();
            $("#validateSummary").append('<li>' + "下記の項目に誤りがあるかご確認下さい。" + '</li>');
                for (var index = 0; index < arrayTextLbl.length; index++) {
                    $("#validateSummary").append('<li>' + arrayTextLbl[index] + '</li>');
                }
            $("#validateSummary").css("display","block");
        }
    }

    //forcus textbox first load page
    $("#main input:text").eq(0).focus();
    
    //var arrayErrorDropDown = [];
    var counterErrorLatLon = 0;
    $("form").submit(function(event) {
        try {
            checkErrorLatLon();
            if ($('#spanError').css("visibility") == "visible" ||$('#spanErrorTwo').css("visibility") == "visible") {
                counterErrorLatLon++;
            } else {
                counterErrorLatLon = 0;
            }
           
        } catch(ex)  {
            
        }
        var arrayError = [];
        $("form input:text,textarea").each(function() {
            try {
                $(this).val($.trim($(this).val()));
                $(this).validate({
                rules: {
                    name: {
                        customname: true
                    }
                },
                errorPlacement: function(error, element) {
                    element.closest("p").prepend(error);
                }
            });
            } catch(ex) {
            }
            
            
            var lengthInputInArray = $(this).attr("maxlength");
            if (typeof lengthInputInArray != "undefined") {
                if (lengthInputInArray.toString() != "undefine") {
                    //Check length of input in array and byte in input
                   var lengByte=getByteLength($(this).val().toString(), 'Shift_JIS');//utf8 is a valid alias
                   // if (lengthInputInArray < lengthUnicode) {
                    if (lengthInputInArray < lengByte) {
                        arrayError.push($(this).attr("textLbl") + "-" + Math.floor(parseInt($(this).attr("maxlength")) / 2).toString());
                    } else {
                        $("span[data-text-displayname-custom='" + $(this).attr("textLbl") + "']").css("display","none");
                    }
                }
            }
        });

        if (arrayError.length >= 1 || counterErrorLatLon != 0) {
            if ($("form").valid()) {
                for (var index = 0; index < arrayError.length; index++) {
                    var textInput = arrayError[index].split("-");
                    $("span[data-text-displayname-custom='" + textInput[0] + "']").css("display","block");
                    $("span[data-text-displayname-custom='" + textInput[0] + "']").text(textInput[0] + " が " + textInput[1] + " " +  $("#constants").val());
                }
            }
            $("#validateSummary").empty();
            $("#validateSummary").append('<li>' + "下記の項目に誤りがあるかご確認下さい。" + '</li>');


            Helpers.addErrorInSummary("form");
            event.preventDefault();
        }
    });
    //End check form submit
});

function getInternetExplorerVersion()
// Returns the version of Internet Explorer or a -1
// (indicating the use of another browser).
{
    var rv = -1; // Return value assumes failure.
    if (navigator.appName == 'Microsoft Internet Explorer')
    {
    var ua = navigator.userAgent;
    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(ua) != null)
        rv = parseFloat( RegExp.$1 );
    }
    return rv;
}

function checkStringByte() {
    
        var arrayError = [];
        $(".divSendAjax input:text,textarea").each(function() {
            $(this).val($.trim($(this).val()));
            $(this).validate({
                rules: {
                    name: {
                        customname: true
                    }
                },
                errorPlacement: function(error, element) {
                    element.closest("p").prepend(error);
                }
            });

            var lengthInputInArray = $(this).attr("maxlength");
            if (typeof lengthInputInArray != "undefined") {
                if (lengthInputInArray.toString() != "undefine") {
                    //Check length of input in array and byte in input
                    var lengByte = getByteLength($(this).val().toString(), 'Shift_JIS'); //utf8 is a valid alias
                    // if (lengthInputInArray < lengthUnicode) {
                    if (lengthInputInArray < lengByte) {
                        arrayError.push($(this).attr("textLbl") + "-" + Math.floor(parseInt($(this).attr("maxlength")) / 2).toString());
                    }
                }
            }
        });

        if (arrayError.length >= 1) {
            if ($("form").valid()) {
                for (var index = 0; index < arrayError.length; index++) {
                    var textInput = arrayError[index].split("-");
                    $("span[data-text-displayname-custom='" + textInput[0] + "']").css("display", "block");
                    $("span[data-text-displayname-custom='" + textInput[0] + "']").text(textInput[0] + " が " + textInput[1] + " " + $("#constants").val());
                }
            }
            $("#validateSummary").empty();
            $("#validateSummary").append('<li>' + "下記の項目に誤りがあるかご確認下さい。" + '</li>');


            Helpers.addErrorInSummary("form");
            return false;
        }
    return true;
}

function checkVersion()
{
    var ver = getInternetExplorerVersion();
    if ( ver > -1 ) {
        if (ver >= 7.0) {
            return true;
        }
        return false;
    }
    return false;
}

function setPositionCenterFor(elementId) {
    var elem = $('#' + elementId);
    
    elem.css("position", "absolute");
    elem.css("top", Math.max(0, (($(window).height() - elem.outerHeight()) / 2) +
        $(window).scrollTop()) + "px");
    elem.css("left", Math.max(0, (($(window).width() - elem.outerWidth()) / 2) +
        $(window).scrollLeft()) + "px");
    //console.log(elem);
    //return elem;
}

// Adding an ID attribute to the inputs you want to validate is simplest
// Better would be to use document.getElementsByTagName and filter the array on NAME
// or use a JQUERY select....
function makeSafe(arrayTextAreaElementId) {
    for (var index = 0; index < arrayTextAreaElementId.length; index++) {
        $("#" + arrayTextAreaElementId[index]).val(window.escape($("#" + arrayTextAreaElementId[index]).val()));
    }
};

// In this case adding the HTML back to a textbox should be 'safe'
// You should be very wary though when you use it as actual HTML
// You MUST take steps to ensure the HTML is safe.
function makeDangerous(arrayTextAreaElementId) {
    //document.getElementById('QuestionAnswer').value = window.unescape(document.getElementById('QuestionAnswer').value);
    for (var index = 0; index < arrayTextAreaElementId.length; index++) {
        $("#" + arrayTextAreaElementId[index]).val(window.unescape($("#" + arrayTextAreaElementId[index]).val()));
    }
}

function checkSelect(arraySelectId, formElementId) {
    var countError = 0;
    var lengthSelect = 0;
    for (var index = 0; index < arraySelectId.length; index++) {
        var textLbl = $("#" + arraySelectId[index]).attr("textLbl");
        $("#" + arraySelectId[index]).find("option:selected").each(function() {
            lengthSelect++;
            var valueOfDropDown = $(this).text();
            if ($.trim(valueOfDropDown) == "") {
                //arrayErrorDropDown.push($(this).attr("textLbl") + "-" + $(this).attr("id"));                        
                $("span[data-check='" + textLbl + "']").css("visibility", "visible");
                $("span[data-check='" + textLbl + "']").text(textLbl + " を選択してください。");

                if ($("span[data-check='" + textLbl + "']").is(':visible')) {
                    countError++;
                }
            } else {
                   $("span[data-check='" + textLbl + "']").css("visibility", "hidden");
            }
            
        });
        if (lengthSelect == 0) {
            $("span[data-check='" + textLbl + "']").css("visibility", "visible");
                $("span[data-check='" + textLbl + "']").text(textLbl + " を選択してください。");
                
                if ($("span[data-check='" + textLbl + "']").is(':visible')) {
                    countError++;
                }
        }
    }
    if (formElementId != "") {
        if (!$(formElementId).valid()) {
            $(formElementId).find('.dropbox-error').each(function() {
                if ($(this).is(':visible')) {

                    $("#validateSummary").css("display", "block");

                    var attr = $(this).text().split(" を選択してください。");

                    // For some browsers, `attr` is undefined; for others,
                    // `attr` is false.  Check for both.
                    if (typeof attr[0] !== 'undefined' && attr[0] !== false) {
                        $("#validateSummary").append('<li>' + attr[0] + '</li>');
                    }
                }
            });
        }
    }
    
    if (countError != 0) {
        return false;
    } else {
	    for(var index = 0;index < arraySelectId.length; index++)
	    {
			var textLbl = $("#" + arraySelectId[index]).attr("textLbl");
			$("span[data-check='" + textLbl + "']").css("visibility", "hidden");
	    }
	    return true;
    }
}

//this function is check error lat lon

function checkErrorLatLon() {

    var countErrorLat = 0;
    var countErrorLon = 0;
    var txtDegree = null;
    var txtMinute = null;
    var txtSecond = null;
    var txtDegree2 = null;
    var txtMinute2 = null;
    var txtSecond2 = null;

    //Latitude check        
    txtDegree = document.getElementById("latitude-degree").value;
    if (replaceString(txtDegree).length < 1 || (!($.isNumeric($("#latitude-degree").val())))) {
        countErrorLat++;
    }

    //check latitude minutes
    txtMinute = document.getElementById("latitude-minute").value;
    if (replaceString(txtMinute).length < 1 || (!($.isNumeric($("#latitude-minute").val())))) {
        countErrorLat++;
    }

    //Latitude check        
    txtDegree = document.getElementById("latitude-degree").value;
    if (replaceString(txtDegree).length < 1 || (!($.isNumeric($("#latitude-degree").val())))) {
        countErrorLat++;
    }

    //check latitude minutes
    txtMinute = document.getElementById("latitude-minute").value;
    if (replaceString(txtMinute).length < 1 || (!($.isNumeric($("#latitude-minute").val())))) {
        countErrorLat++;
    }
    //check latitude minutes
    txtSecond = document.getElementById("latitude-second").value;
    if (replaceString(txtSecond).length < 1 || (!($.isNumeric($("#latitude-second").val())))) {
        countErrorLat++;
    }

    //check longitude degree
    txtDegree2 = document.getElementById("longitude-degree").value;
    if (replaceString(txtDegree2).length < 1 || (!($.isNumeric($("#longitude-degree").val())))) {
        countErrorLon++;
    }
    //check longitude minute
    txtMinute2 = document.getElementById("longitude-minute").value;
    if (replaceString(txtMinute2).length < 1 || (!($.isNumeric($("#longitude-minute").val())))) {
        countErrorLon++;
    }
    //check longitude second
    txtSecond2 = document.getElementById("longitude-second").value;
    if (replaceString(txtSecond2).length < 1 || (!($.isNumeric($("#longitude-second").val())))) {
        countErrorLon++;
    }
    if (countErrorLat != 0) {
        $("#spanError").css("visibility", "visible");
        $("#spanError").text("緯度を正しく入力してください");
    } else {
        $("#spanError").css("visibility", "hidden");
    }
    if (countErrorLon != 0) {
        $("#spanErrorTwo").css("visibility", "visible");
        $("#spanErrorTwo").text("経度を正しく入力してください");
    } else {

        $("#spanErrorTwo").css("visibility", "hidden");
    }
    if (countErrorLat == 0 && countErrorLon == 0) {
        txtSecond = txtSecond.toString().replace(",", ".");
        txtSecond2 = txtSecond2.toString().replace(",", ".");
        var latitude = parseFloat(txtDegree) + parseFloat(txtMinute / 60) + parseFloat(txtSecond / 3600);
        var longitude = parseFloat(txtDegree2) + parseFloat(txtMinute2 / 60) + parseFloat(txtSecond2 / 3600);
        this.focusLocationAddress(longitude, latitude);
        return true;
    } else {
        return false;
    }
}

//Method focused to location on Map

function focusLocationAddress(longitude, latitude) {

    var wordRange = new Array();
    var arrayRangeMap = window.GisMapUrls.rangeMap;
    wordRange = arrayRangeMap.split(' ');

    if (longitude < 0)
        longitude = longitude * -1;
    if (latitude < 0) {
        latitude = latitude * -1;
    }

    if ((longitude > wordRange[0] && longitude < wordRange[2]) && (latitude > wordRange[1] && latitude < wordRange[3])) {
        $("#spanError").css("visibility", "hidden");
        $("#spanErrorTwo").css("visibility", "hidden");
        return false;
    } else if ((longitude < wordRange[0] || longitude > wordRange[2])) {
        $("#spanErrorTwo").css("visibility", "visible");
        $("#spanErrorTwo").text("緯度を正しく入力してください");

    } else if ((latitude < wordRange[1] || latitude > wordRange[3])) {
        $("#spanError").css("visibility", "visible");
        $("#spanError").text("経度を正しく入力してください");
    }
}

//This function is replace string 

function replaceString(str) {
    return str.replace(/^\s+|\s+$/, '');
}

function getByteLength(textString)
{
	var total = 0;
	var LOG2_256 = 8;
	var LN2x8 = Math.LN2 * LOG2_256;
	
	for(var i = 0; i < textString.length; i++){
		total += Math.ceil(Math.log(textString[i].charCodeAt()) / LN2x8);
	}
	
	return total;
}